<!DOCTYPE html><html lang="cn" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Ansible基础 | 碧蓝幻想</title><meta name="author" content="阿尔托莉雅"><meta name="copyright" content="阿尔托莉雅"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1.Ansible的概念： 什么是Ansible： Ansible是近年越来越火的基于python开发的一款运维自动化工具 主要帮助运维实现IT工作的自动化、降低人为操作失误、提高业务自动化率、提高运维工作效率 Ansible是基于模块来运行，它本身没有任何批量部署的能力，Ansible主要是提供一种批量部署的框架 常用于软件部署自动化、配置自动化、管理自动化、系统化系统任务、持续集成、零宕机平滑">
<meta property="og:type" content="article">
<meta property="og:title" content="Ansible基础">
<meta property="og:url" content="http://example.com/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/index.html">
<meta property="og:site_name" content="碧蓝幻想">
<meta property="og:description" content="1.Ansible的概念： 什么是Ansible： Ansible是近年越来越火的基于python开发的一款运维自动化工具 主要帮助运维实现IT工作的自动化、降低人为操作失误、提高业务自动化率、提高运维工作效率 Ansible是基于模块来运行，它本身没有任何批量部署的能力，Ansible主要是提供一种批量部署的框架 常用于软件部署自动化、配置自动化、管理自动化、系统化系统任务、持续集成、零宕机平滑">
<meta property="og:locale">
<meta property="og:image" content="http://example.com/images/Otherwallpaper/avatar.png">
<meta property="article:published_time" content="2023-03-13T12:32:23.861Z">
<meta property="article:modified_time" content="2023-03-13T12:39:46.483Z">
<meta property="article:author" content="阿尔托莉雅">
<meta property="article:tag" content="Linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/images/Otherwallpaper/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Ansible基础',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-03-13 20:39:46'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/images/Otherwallpaper/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/images/PCwallpaper/backgroud2.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="碧蓝幻想"><span class="site-name">碧蓝幻想</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archive/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 工具</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/images/"><i class="fa-fw fas fa-image"></i><span> 图库</span></a></li><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/video/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Ansible基础</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-03-13T12:32:23.861Z" title="Created 2023-03-13 20:32:23">2023-03-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-03-13T12:39:46.483Z" title="Updated 2023-03-13 20:39:46">2023-03-13</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Linux/">Linux</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Ansible基础"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="1-Ansible的概念："><a href="#1-Ansible的概念：" class="headerlink" title="1.Ansible的概念："></a>1.Ansible的概念：</h2><ul>
<li>什么是Ansible：<ul>
<li>Ansible是近年越来越火的基于python开发的一款<strong>运维自动化工具</strong></li>
<li>主要帮助运维实现IT工作的自动化、降低人为操作失误、提高业务自动化率、提高运维工作效率</li>
<li><strong>Ansible是基于模块来运行，它本身没有任何批量部署的能力，Ansible主要是提供一种批量部署的框架</strong></li>
<li>常用于软件部署自动化、配置自动化、管理自动化、系统化系统任务、持续集成、零宕机平滑升级等</li>
<li>ansible可以批量修改服务器密码，批量安装软件包，批量修改配置</li>
</ul>
</li>
<li>为什么选择Ansible：<ul>
<li>方便对Ansible的二次开发</li>
<li>Ansible丰富的内置模块</li>
<li>在Ansible去中心化概念</li>
<li>Agentless（无客户端）</li>
</ul>
</li>
<li>Ansible优点：<ul>
<li>轻量级，他不需要去客户端安装agent，更新时，只需要在操作机上进行一次更新即可</li>
<li>批量任务执行可以写成脚本，而且不用分发到远程就可以执行</li>
<li>使用python编写的，维护更简单</li>
<li>支持sudo</li>
</ul>
</li>
<li>Ansible缺点：对于几千台、上万台机器的操作，还不清楚性能、效率情况如何，需要进一步了解</li>
</ul>
<h2 id="2-Ansible应用领域："><a href="#2-Ansible应用领域：" class="headerlink" title="2.Ansible应用领域："></a>2.Ansible应用领域：</h2><p>- </p>
<h2 id="3-Ansible架构模式："><a href="#3-Ansible架构模式：" class="headerlink" title="3.Ansible架构模式："></a>3.Ansible架构模式：</h2><ul>
<li><p>Ansible 管理方式：</p>
<ul>
<li><p>Ansible 是一个模型驱动的配置管理器， 支持多节点发布、 远程任务执行</p>
</li>
<li><p><strong>默认使用SSH 进行远程连接</strong>。 无需在被管节点上安装附加软件， 可使用各种编程语言进行扩展</p>
</li>
<li><p>图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230216223814116.png" alt="image-20230216223814116"></p>
</li>
</ul>
</li>
<li><p>Ansible系统架构：</p>
<ul>
<li><p>Ansible 是基于模块工作的， 本身没有批量部署的能力；真正具有批量部署的是 Ansible 所运行的模块， Ansible只是提供一种框架</p>
</li>
<li><p>Ansible组成图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230217091403862.png" alt="image-20230217091403862"></p>
</li>
<li><p>Ansible 由以下各部分组成:</p>
<ul>
<li>核心引擎：即 Ansible，执行工具；一次性或者临时执行的操作都是通过该命令进行。</li>
<li>剧本（playbook)：<strong>定义Ansible任务的配置文件</strong>，可以将多个任务定义在一个剧本中，Ansible自动执行，剧本执行支持多个任务，可以由控制主机运行多个任务,同时对多台远程主机进行管理。</li>
<li>主机清单（host inventory)：定义Ansible管理的主机策略，默认是在Ansible的hosts配置文件<strong>中定义被管节点</strong></li>
<li>核心模块（core modules )：这些都是Ansible自带的模块。</li>
<li>自定义模块（custom modules)：如果核心模块不足以完成某种功能,可以添加自定义模块。 </li>
<li>插件（plugins)：完成模块功能的补充，借助于插件完成记录日志,邮件等功能。</li>
<li>连接插件（connectior plugins)：Ansible 基于连接插件连接到各个主机上，负责和被管节点实现通信。</li>
</ul>
</li>
<li><p>Ansible的作用对象，不仅是Linux和非Linux操作系统的主机，同样也可以作用于各类公&#x2F;私有云、商业&#x2F;非商业设备的网络设施</p>
</li>
</ul>
</li>
</ul>
<h2 id="4-Ansible执行过程："><a href="#4-Ansible执行过程：" class="headerlink" title="4.Ansible执行过程："></a>4.Ansible执行过程：</h2><ul>
<li><p>过程图示：</p>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230217091819425.png" alt="image-20230217091819425"></p>
</li>
<li><p>使用者使用ansible或ansible-playbook(会额外读取playbook文件)时,在服务器终端输入ansible的ad-hoc命令集或playbook后,ansible会遵循预先编排的规则将playbooks逐条拆解为play,再将play组织成ansible可识别的任务(task)。</p>
</li>
<li><p>随后调用任务涉及的所有模块(module)和插件(plugin),根据inventory中定义的主机列表通过ssh将任务集以临时文件或命令的形式传输到远程客户端执行并返回执行结果,如果临时文件执行完毕则自动删除.</p>
</li>
</ul>
<h2 id="5-Ansible的特性："><a href="#5-Ansible的特性：" class="headerlink" title="5.Ansible的特性："></a>5.Ansible的特性：</h2><ul>
<li>应用代码自动化部署。 </li>
<li>系统管理配置自动化。</li>
<li>支持持续交付自动化。</li>
<li>支持云计算 、大数据平台（ 如 AWS、 OpenStack 、 CloudStack 、 VMWare 等） 环境。 </li>
<li>轻量级， 无需在客户端安装 agent， 更新时只需在控制机上进行一次更新即可。</li>
<li>批量任务执行可以写成脚本， 不用分发到远程就可以执行。</li>
<li>使用 Python 编写，维护更简单， Ruby 语法过于复杂。 </li>
<li>支持非 root 用户管理操作， 支持 sudo。</li>
</ul>
<h2 id="6-Ansible安装与配置："><a href="#6-Ansible安装与配置：" class="headerlink" title="6.Ansible安装与配置："></a>6.Ansible安装与配置：</h2><h3 id="1-环境配置："><a href="#1-环境配置：" class="headerlink" title="1.环境配置："></a>1.环境配置：</h3><table>
<thead>
<tr>
<th>角色</th>
<th>主机名</th>
<th>ip地址</th>
</tr>
</thead>
<tbody><tr>
<td>控制主机</td>
<td>quruixiang.com</td>
<td>192.168.178.101</td>
</tr>
<tr>
<td>受控主机&#x2F;被管节点</td>
<td>wangxuan.com</td>
<td>192.168.178.151</td>
</tr>
<tr>
<td>受控主机&#x2F;被管节点</td>
<td>zhanglin.com</td>
<td>192.168.178.201</td>
</tr>
</tbody></table>
<ul>
<li><p>三个主机配置从服务器的ip</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">nmcli connection modify ens160 ipv4.addresses 172.25.178.201/24</span><br><span class="line">nmcli connection up ens160</span><br></pre></td></tr></table></figure>
</li>
<li><p>三个主机关闭防火墙和selinux</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">systemctl stop firwalld</span><br><span class="line">systemctl disable firwalld</span><br><span class="line">sed -i &#x27;s/SELINUX=enforcing/SELINUX=disabled/g&#x27; /etc/selinux/config</span><br><span class="line">setenforce 0</span><br><span class="line">shutdown -r</span><br></pre></td></tr></table></figure>
</li>
<li><p>三个主机配置主机名：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">hostnamectl set-hostname [主机名]</span><br></pre></td></tr></table></figure>
</li>
<li><p>anbile主机（控制主机）生成秘钥对，复制到其他主机（受控主机）上，实现免密登录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -b [字节数]</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">~/.ssh/id_rsa私钥文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">~/.ssh/id_rsa.pub公钥文件</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">方式一复制：</span></span><br><span class="line">scp [本地的公钥文件路径] root@[IP地址]:/root/.ssh/authorized_keys     # 复制公钥</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">方式二复制：</span></span><br><span class="line">ssh-copy-id -i ~/.ssh/id_rsa.pub student@192.168.178.151</span><br></pre></td></tr></table></figure>
</li>
<li><p>在anbile主机（控制主机）的hosts配置域名解析：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/hosts</span><br><span class="line"># 添加内容</span><br><span class="line">[IP地址] [域名]</span><br><span class="line">......</span><br></pre></td></tr></table></figure>
</li>
<li><p>设置三个节点时间同步：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">yum install -y chrony</span><br><span class="line">vim /etc/chrony.conf</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">主服务器修改内容</span></span><br><span class="line">server ntp.aliyun.com iburst      # 配置网络同步时间服务器地址，阿里云</span><br><span class="line">allow 192.168.178.0/24            # 允许同步的客户端地址范围</span><br><span class="line">local stratum 10                  # 也在向其他服务器提供时间服务</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">从服务器修改内容</span></span><br><span class="line">server quruixiang.com iburst      # 配置网络同步时间服务器地址，主服务器地址</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">systemctl restart chronyd</span><br><span class="line">systemctl enable chronyd</span><br><span class="line">tiemdatectl status                   # 查看时间同步状态</span><br><span class="line">timedatectl set-ntp true             # 开启网络时间同步</span><br><span class="line">chronyc sources -v                   # 查看 ntp_servers，-v 详细信息</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">显示内容</span></span><br><span class="line">  .-- Source mode  &#x27;^&#x27; = server, &#x27;=&#x27; = peer, &#x27;#&#x27; = local clock.</span><br><span class="line"> / .- Source state &#x27;*&#x27; = current best, &#x27;+&#x27; = combined, &#x27;-&#x27; = not combined,</span><br><span class="line">| /             &#x27;x&#x27; = may be in error, &#x27;~&#x27; = too variable, &#x27;?&#x27; = unusable.</span><br><span class="line">||                                                 .- xxxx [ yyyy ] +/- zzzz</span><br><span class="line">||      Reachability register (octal) -.           |  xxxx = adjusted offset,</span><br><span class="line">||      Log2(Polling interval) --.      |          |  yyyy = measured offset,</span><br><span class="line">||                                \     |          |  zzzz = estimated error.</span><br><span class="line">||                                 |    |           \</span><br><span class="line">MS Name/IP address         Stratum Poll Reach LastRx Last sample               </span><br><span class="line">===============================================================================</span><br><span class="line">^- ns.gmgnet.ch                  2   7   377   122  +5684us[+5803us] +/-  127ms</span><br><span class="line">^- 44.190.5.123                  2   7    77   125  -1062us[ -933us] +/-   89ms</span><br><span class="line">^- lithium.constant.com          2   7   177   127  +7536us[+7663us] +/-  166ms</span><br><span class="line">^- nux.hackeriet.no              2   7   377   127    -30ms[  -30ms] +/-  128ms</span><br><span class="line">^* quruixiang.com                3   6   377     1    +28us[  +53us] +/-   23ms</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="2-安装："><a href="#2-安装：" class="headerlink" title="2.安装："></a>2.安装：</h3><ul>
<li><p>必须清空&#x2F;etc&#x2F;yum.repos.d目录下的所有仓库文件</p>
</li>
<li><p>导入Centos-Stream.repo仓库文件：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">链接：https://pan.baidu.com/s/11O4n1d6IZHVBab-dCVy44A </span><br><span class="line">提取码：icde</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">如下文件仓库内容</span></span><br><span class="line">[base]</span><br><span class="line">name=CentOS-8-stream - Base - mirrors.aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/8-stream/BaseOS/$basearch/os/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">additional packages that may be useful</span></span><br><span class="line">[extras]</span><br><span class="line">name=CentOS-8-stream - Extras - mirrors.aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/8-stream/extras/$basearch/os/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">additional packages that extend functionality of existing packages</span></span><br><span class="line">[centosplus]</span><br><span class="line">name=CentOS-8-stream - Plus - mirrors.aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/8-stream/centosplus/$basearch/os/</span><br><span class="line">gpgcheck=1</span><br><span class="line">enabled=0</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official</span><br><span class="line"></span><br><span class="line">[PowerTools]</span><br><span class="line">name=CentOS-8-stream - PowerTools - mirrors.aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/8-stream/PowerTools/$basearch/os/</span><br><span class="line">gpgcheck=1</span><br><span class="line">enabled=0</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official</span><br><span class="line"></span><br><span class="line">[AppStream]</span><br><span class="line">name=CentOS-8-stream - AppStream - mirrors.aliyun.com</span><br><span class="line">baseurl=https://mirrors.aliyun.com/centos/8-stream/AppStream/$basearch/os/</span><br><span class="line">gpgcheck=1</span><br><span class="line">gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official</span><br></pre></td></tr></table></figure>
</li>
<li><p>验证是否安装成功：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum repolist</span><br></pre></td></tr></table></figure>
</li>
<li><p>Ansible仓库默认不在yum仓库中，因此需要使用下面的命令启用epel仓库</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm</span><br><span class="line">sed -i &#x27;s|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|&#x27; /etc/yum.repos.d/epel*</span><br><span class="line">sed -i &#x27;s|^metalink|#metalink|&#x27; /etc/yum.repos.d/epel*</span><br></pre></td></tr></table></figure>
</li>
<li><p>安装Ansible工具：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y ansible</span><br></pre></td></tr></table></figure>
</li>
<li><p>是否安装成功：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible –-version</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="7-清单文件指定受管主机："><a href="#7-清单文件指定受管主机：" class="headerlink" title="7.清单文件指定受管主机："></a>7.清单文件指定受管主机：</h2><h3 id="1-概念："><a href="#1-概念：" class="headerlink" title="1.概念："></a>1.概念：</h3><ul>
<li>清单中定义ansible将要管理的一批主机，这些主机也可以分配到组中，以进行集中管理。组中也可以包含子组，一台主机也可以是多个组中的成员。清单还可以设置应用到它所定义的主机和组的变量。</li>
<li>定义主机清单的两种方式：<ul>
<li>静态主机清单：可以通过文本文件定义</li>
<li>动态主机清单：可以根据需要使用外部信息提供程序通过脚本或其他程序生成。</li>
</ul>
</li>
</ul>
<h3 id="2-静态文件清单："><a href="#2-静态文件清单：" class="headerlink" title="2.静态文件清单："></a>2.静态文件清单：</h3><ul>
<li><p>默认安装ansible匹配的主机清单文件是&#x2F;etc&#x2F;ansible&#x2F;hosts</p>
</li>
<li><p>修改&#x2F;etc&#x2F;ansible&#x2F;hosts文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/ansible/hosts</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改类型1：直接添加主机名</span></span><br><span class="line">wangxuan.com </span><br><span class="line">zhanglin.com</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改类型2：使用主机组</span></span><br><span class="line">[webservers]</span><br><span class="line">wangxuan.com</span><br><span class="line">zhanglin.com</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改类型3：使用嵌套主机组</span></span><br><span class="line">[webservers:gourp1]</span><br><span class="line">wangxuan.com</span><br><span class="line">zhanglin.com</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改类型3：使用范围指定 [start:end]</span></span><br><span class="line">node[1:3].com</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">完整格式：</span></span><br><span class="line">wangxuan.com  ansible_ssh_port=[ssh端口]  ansible_ssh_user=[用户] ansible_ssh_pass=[登录密码]  ansible_sudo_pass=[sudo密码]</span><br><span class="line">192.168.178.151  ansible_ssh_port=[ssh端口]  ansible_ssh_user=[用户] ansible_ssh_pass=[登录密码]  ansible_sudo_pass=[sudo密码]</span><br></pre></td></tr></table></figure>
</li>
<li><p>验证清单：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">方式一：</span></span><br><span class="line">ansible [主机组名] --list-hosts</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">参数：</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">[主机组名] 指定清单文件的主机组名</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="string">&quot;匹配字段&quot;</span> 指定清单文件的主机组名</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">all 主机组含有清单中明确列出的每一个主机</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">ungrouped 主机组含有清单中明确列出、但不属于任何其他组的每一个主机</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">方式二：图形化查看所有主机</span></span><br><span class="line">ansible-inventory  --graph</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-自定义静态主机清单："><a href="#3-自定义静态主机清单：" class="headerlink" title="3.自定义静态主机清单："></a>3.自定义静态主机清单：</h3><ul>
<li><p>在某个工作目录下创建一个名为inventory的自定义静态主机清单文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mkdir deploy-inventory </span><br><span class="line">cd deploy-inventory</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vim inventory</span><br><span class="line"># 修改内容如下：</span><br><span class="line"> [web] </span><br><span class="line">192.168.178.51</span><br></pre></td></tr></table></figure>
</li>
<li><p>验证清单：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible all -i [自定义清单文件路径]   --list-hosts</span><br></pre></td></tr></table></figure>
</li>
<li><p>测试连通性：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible -i [自定义清单文件路径] -m ping</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="8-管理ansible的配置文件："><a href="#8-管理ansible的配置文件：" class="headerlink" title="8.管理ansible的配置文件："></a>8.管理ansible的配置文件：</h2><ul>
<li><p>查看当前ansible使用的配置文件：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible --version</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改默认的配置文件：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/ansible/ansible.cfg</span><br></pre></td></tr></table></figure>
</li>
<li><p>配置文件详情：</p>
<p>配置文件由几部分组成，每部分含有以键值对形式定义的设置。部分的标题以方括号括起。重点需要了解以下<strong>两部分</strong>：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[defaults]</span><br><span class="line">inventory = ./inventory            #主机列表配置文件（如果没有自定义就不用配置）</span><br><span class="line">library = /usr/share/my_modules    #库文件存放目录</span><br><span class="line">forks = 5                          #默认并发数5 （同时可以处理5个命令--同时有20个节点主机5个主机执行在5个执行）</span><br><span class="line">sudo_user = root                   #默认的sudo用户 root</span><br><span class="line">ask_sudo_pass = ture               #每次sudo是否提示咨询密码，</span><br><span class="line">ask_pass = false                   #每次执行命令是否询问ssh密码（对方用户的密码），为true一定咨询，可以通过-k指定</span><br><span class="line">remout_port = 22        </span><br><span class="line">host_key_checking = false          #检查被控节点的host_key，如果配置了免密就false此属性</span><br><span class="line">log_path = /var/log/ansible.log    #ansible日志文件</span><br><span class="line">module_name = command              #默认模块，可以改为shell</span><br><span class="line">remote_user = user                 #要在受管主机上登录的用户名称，没有指定则是当前用户（受管、管控、托管主机的用户名）</span><br><span class="line">remote_tmp = ~/.ansible/tmp;       #临时的py命令文件存放在远程主机目录</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">特权升级，控制主机执行特权命令不需要指定sudo命令</span> </span><br><span class="line">[privilege_escalation]             </span><br><span class="line">become = true                      #连接后是否在受管主机上切换用户，默认会切换到root下</span><br><span class="line">become_method = sudo               #如何切换用户</span><br><span class="line">become_user = root                 #受管主机切换到的用户</span><br><span class="line">become_ask_pass = false            #是否为become_method提示输入密码，默认为false</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="9-ansible-hoc命令："><a href="#9-ansible-hoc命令：" class="headerlink" title="9.ansible-hoc命令："></a>9.ansible-hoc命令：</h2><ul>
<li><p>概念：</p>
<ul>
<li>Ad-hoc是指ansible下临时执行的一条命令，并且不需要保存的命令对于复杂的命令会使用playbook</li>
<li>Ad-hocd的执行依赖于模块</li>
</ul>
</li>
<li><p>参数：</p>
<table>
<thead>
<tr>
<th>首个参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>[主机组名]</td>
<td>指定清单文件的主机组名</td>
</tr>
<tr>
<td>“匹配字段”</td>
<td>指定清单文件的主机组名</td>
</tr>
<tr>
<td>all</td>
<td>主机组含有清单中明确列出的每一个主机</td>
</tr>
<tr>
<td>ungrouped</td>
<td>主机组含有清单中明确列出、但不属于任何其他组的每一个主机</td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th>其他参数</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>-m（module）</td>
<td>指定使用的模块，默认使用” command “</td>
</tr>
<tr>
<td>-i</td>
<td>指定ansible自定义清单文件的路径</td>
</tr>
<tr>
<td>-v（verbose）</td>
<td>如果命令执行成功，输出详细的结果</td>
</tr>
<tr>
<td>-u （user）</td>
<td>ssh连接的用户名，默认用root，ansible.cfg中可以配置</td>
</tr>
<tr>
<td>-a</td>
<td><strong>指定module模块的参数</strong>（命令）</td>
</tr>
<tr>
<td>-k</td>
<td>提示输入ssh登录密码，当使用密码验证的时候用</td>
</tr>
<tr>
<td>–list-host</td>
<td>只打印有哪些主机会执行这个命令，不会实际执行</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible [主机组名] -a &quot;uptime&quot;    # 检查ansible被管理节点的cpu负载</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible [主机组名] -a &quot;useradd student&quot;     # 给ansible被管理节点增加用户</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible [主机组名] -a &quot;grep root /etc/passwd&quot;     # 查看被控结点中的/etc/passwd文件的内容</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible [主机组名] -a &quot;ls -l /&quot;     # 查看被控结点中根目录下的文件</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -a &quot;echo This is world&quot;     # 在被控节点控制台输出语句</span><br></pre></td></tr></table></figure>

<table>
<thead>
<tr>
<th>匹配字段通配符</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>*</td>
<td>任意字符或多个字符</td>
</tr>
<tr>
<td>[主机组名1:主机组名2]</td>
<td>组1和组2的并集</td>
</tr>
<tr>
<td>[主机组名1:&amp;主机组名2]</td>
<td>组1和组2的交集</td>
</tr>
<tr>
<td>[主机组名1:!主机组名2]</td>
<td>属于组1但不属于组2</td>
</tr>
<tr>
<td>~</td>
<td>表示开始正则匹配</td>
</tr>
<tr>
<td>\</td>
<td>转义</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible &quot;wangxuan*&quot; -a &quot;ls -l /&quot;      # 查看被控结点中匹配wangxuanh后跟任意多个字符的主机根目录下的文件</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="10-案例："><a href="#10-案例：" class="headerlink" title="10.案例："></a>10.案例：</h2><h3 id="1-使用普通用户连接："><a href="#1-使用普通用户连接：" class="headerlink" title="1.使用普通用户连接："></a>1.使用普通用户连接：</h3><ul>
<li><p>通过ansible批量创建用户：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible -a &quot;useradd student&quot; webservers</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过ansible批量修改用户密码：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible -a &quot;echo &#x27;123456&#x27; | passwd --stdin student&quot; webservers</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过ansible批量删除root用户的authorized_keys文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible -a &quot;rm -rf /root/.ssh/authorized_keys&quot; webservers</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改配置文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/ansible/ansilbe.cfg</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改内容</span></span><br><span class="line">[defaults]</span><br><span class="line">inventory=/etc/ansible/hosts         # 必须指定默认的清单文件，不让还是root用户</span><br><span class="line">remote_user=student                  # 指定默认连接到被控节点的用户</span><br><span class="line">ask_pass=false                       # 每次执行ansible命令是否询问ssh密码</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="2-关闭主机秘钥验证："><a href="#2-关闭主机秘钥验证：" class="headerlink" title="2.关闭主机秘钥验证："></a>2.关闭主机秘钥验证：</h3><ul>
<li><p>在受管主机中通过ssh远程连接方式（没有配置免密登录）以student用户身份执行，并验证密码；如果ask_pass为false 则可以通过-k 来指定密码</p>
</li>
<li><p>修改配置文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/ansible/ansilbe.cfg</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改内容</span></span><br><span class="line">[defaults]</span><br><span class="line">host_key_checking = False          #检查对应服务器的host_key，建议取消注释</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="3-远程用户sudo提权："><a href="#3-远程用户sudo提权：" class="headerlink" title="3.远程用户sudo提权："></a>3.远程用户sudo提权：</h3><ul>
<li><p>在受管主机中需要通过管理员身份运行命令则配置sudo</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/sudoers</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改内容,如果配置了NOPASSWD: ALL，配置ask_sudo_pass = ture 是不咨询密码的</span></span><br><span class="line">student    ALL=(ALL)   NOPASSWD: ALL</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="11-ansible-doc模块："><a href="#11-ansible-doc模块：" class="headerlink" title="11.ansible-doc模块："></a>11.ansible-doc模块：</h2><table>
<thead>
<tr>
<th>ansible-doc</th>
<th>详细参数</th>
</tr>
</thead>
<tbody><tr>
<td>-l（list）</td>
<td>列出所有的模块列表</td>
</tr>
<tr>
<td>-s</td>
<td>查看指定模块的参数</td>
</tr>
<tr>
<td>[模块]</td>
<td>查看具体模块的具体帮助</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible-doc -l | grep yum      # 查看yum模块</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible-doc ping 	</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ansible-doc yum_repository</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用/EXAM查询此模块剧本的例子</span></span><br></pre></td></tr></table></figure>



<h2 id="12-ansible执行颜色："><a href="#12-ansible执行颜色：" class="headerlink" title="12.ansible执行颜色："></a>12.ansible执行颜色：</h2><table>
<thead>
<tr>
<th>颜色</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>绿色</td>
<td>执行成功并且不需要做出任何改变</td>
</tr>
<tr>
<td>黄色</td>
<td>执行成功并且对目标主机做出变更</td>
</tr>
<tr>
<td>红色</td>
<td>执行失败</td>
</tr>
<tr>
<td>蓝色</td>
<td>显示详细过程</td>
</tr>
<tr>
<td>紫色</td>
<td>显示警告</td>
</tr>
</tbody></table>
<h2 id="13-ansible的模块："><a href="#13-ansible的模块：" class="headerlink" title="13.ansible的模块："></a>13.ansible的模块：</h2><h3 id="1-四个命令模块："><a href="#1-四个命令模块：" class="headerlink" title="1.四个命令模块："></a>1.四个命令模块：</h3><ul>
<li><p>应尽量避免使用这三个模块来执行命令，因为其他模块大部分都是幂等性的可以自动进行更改跟踪。command、shell、raw不具备幂等性</p>
</li>
<li><p>注： 幂等性：简单来讲，就是输入相同，输出相同，无论多少次比如说，确认接口，如果传入订单号，返回确认OK，如果已经确认过了，再次调用确认接口，返回如果还是确认OK，那么这个接口就是满足幂等性.</p>
</li>
<li><p>三者的区别：</p>
<ul>
<li>相同点：要求受管主机上安装Python。</li>
<li>不同点：<ul>
<li>command可以在受管主机上执行shell命令，<strong>但是不支持环境变量和操作符（例如 ‘|’, ‘&lt;’, ‘&gt;’, ‘&amp;’）</strong></li>
<li>shell模块调用的&#x2F;bin&#x2F;sh指令执行，用法和command基本一致，所以shell可以执行任何命令，推荐使用。</li>
<li>script模块将本机文件放到远程主机执行，<strong>不需要复制文件</strong></li>
<li>raw模块<strong>不需要受管主机上安装Python</strong>，直接使用远程shell运行命令，通常用于无法安装Python的系统（例如网络设备等）。</li>
</ul>
</li>
</ul>
</li>
<li><p>command模块：</p>
<ul>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th><strong>名称</strong></th>
<th><strong>必选</strong></th>
<th><strong>备注</strong></th>
</tr>
</thead>
<tbody><tr>
<td>chdir</td>
<td>no</td>
<td>运行command命令前先cd到这个目录</td>
</tr>
<tr>
<td>creates</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就不运行command</td>
</tr>
<tr>
<td>free_form</td>
<td>yes</td>
<td>需要执行的脚本（没有真正的参数为free_form）只是一种参数模式name&#x3D;value</td>
</tr>
<tr>
<td>executable</td>
<td>no</td>
<td>改变用来执行命令的shell，应该是可执行文件的绝对路径。</td>
</tr>
<tr>
<td>removes</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就运行command，与creates参数的作用相反</td>
</tr>
<tr>
<td>stdin(2.4后新增)</td>
<td>no</td>
<td>将命令的stdin设置为指定的值</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看当前目录下的文件时，先切换到/usr/qv123的目录下</span></span><br><span class="line">ansible webservers -a &quot;ls -l chdir=/usr/qv123&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">因为creates的文件在root目录下不存在，所以执行命令</span></span><br><span class="line">ansible test -m command -a &quot;ls /root creates=test.sh&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">因为removes的文件在root目录下不存在，所以不执行命令</span></span><br><span class="line">ansible webservers -a &quot;ls / removes=test.sh&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -a &quot;cd /usr/qv123;ls -l&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>shell模块：</p>
<ul>
<li><p>让远程主机在shell进程下执行命令，从而支持shell的特性，如管道等。与command模块几乎相同，但在执行命令的时候使用的是&#x2F;bin&#x2F;sh。</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th><strong>名称</strong></th>
<th><strong>必选</strong></th>
<th><strong>备注</strong></th>
</tr>
</thead>
<tbody><tr>
<td>chdir</td>
<td>no</td>
<td>运行command命令前先cd到这个目录</td>
</tr>
<tr>
<td>creates</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就不运行command</td>
</tr>
<tr>
<td>executable</td>
<td>no</td>
<td>改变用来执行命令的shell，应该是可执行文件的绝对路径。</td>
</tr>
<tr>
<td>free_form</td>
<td>yes</td>
<td>需要执行的脚本（没有真正的参数为free_form）只是一种参数模式name&#x3D;value</td>
</tr>
<tr>
<td>removes</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就运行command，与creates参数的作用相反</td>
</tr>
<tr>
<td>stdin(2.4后新增)</td>
<td>no</td>
<td>将命令的stdin设置为指定的值</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m shell -a &quot;sudo ./test.sh chdir=/usr/qv123&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -a &quot;cd /usr/qv123;ls -l&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>script模块：</p>
<ul>
<li><p>在远程主机上执行主控主机上的脚本（不需要将文件复制到远程主机）</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th><strong>名称</strong></th>
<th><strong>必选</strong></th>
<th><strong>备注</strong></th>
</tr>
</thead>
<tbody><tr>
<td>chdir</td>
<td>no</td>
<td>运行command命令前先cd到这个目录</td>
</tr>
<tr>
<td>creates</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就不运行command</td>
</tr>
<tr>
<td>executable</td>
<td>no</td>
<td>改变用来执行命令的shell，应该是可执行文件的绝对路径。</td>
</tr>
<tr>
<td>free_form</td>
<td>yes</td>
<td>需要执行的脚本（没有真正的参数为free_form）只是一种参数模式name&#x3D;value</td>
</tr>
<tr>
<td>removes</td>
<td>no</td>
<td>如果这个参数对应的文件存在，就运行command，与creates参数的作用相反</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@quruixiang myShell]# ansible webservers -m script -a &quot;./test.sh&quot;</span><br><span class="line">wangxuan.com | CHANGED =&gt; &#123;</span><br><span class="line">    &quot;changed&quot;: true,</span><br><span class="line">    &quot;rc&quot;: 0,</span><br><span class="line">    &quot;stderr&quot;: &quot;Shared connection to wangxuan.com closed.\r\n&quot;,</span><br><span class="line">    &quot;stderr_lines&quot;: [</span><br><span class="line">        &quot;Shared connection to wangxuan.com closed.&quot;</span><br><span class="line">    ],</span><br><span class="line">    &quot;stdout&quot;: &quot;我被执行了。。。。。。\r\n&quot;,</span><br><span class="line">    &quot;stdout_lines&quot;: [</span><br><span class="line">        &quot;我被执行了。。。。。。&quot;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>raw模块：</p>
<ul>
<li><p>raw模块主要用于执行一些低级的，脏的SSH命令，而不是通过command模块。 </p>
</li>
<li><p>raw模块只适用于下列两种场景，第一种情况是在较老的（Python 2.4和之前的版本）主机上，另一种情况是对任何没有安装Python的设备（如路由器）。 在任何其他情况下，使用shell或command模块更为合适。</p>
</li>
<li><p>就像script模块一样，raw模块不需要远程系统上的python</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th><strong>名称</strong></th>
<th><strong>必选</strong></th>
<th><strong>备注</strong></th>
</tr>
</thead>
<tbody><tr>
<td>executable</td>
<td>no</td>
<td>改变用来执行命令的shell，应该是可执行文件的绝对路径。</td>
</tr>
<tr>
<td>free_form</td>
<td>yes</td>
<td>需要执行的脚本（没有真正的参数为free_form）</td>
</tr>
</tbody></table>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m raw -a &quot;pwd&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="2-八个文件模块："><a href="#2-八个文件模块：" class="headerlink" title="2.八个文件模块："></a>2.八个文件模块：</h3><ul>
<li><h3 id="file模块："><a href="#file模块：" class="headerlink" title="file模块："></a>file模块：</h3><ul>
<li><p>file模块可以帮助我们完成一些对文件的基本操作，比如，创建文件或目录、删除文件或目录、修改文件权限等</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>path</td>
<td>yes</td>
<td>用于指定要操作的文件或目录</td>
</tr>
<tr>
<td>state</td>
<td>yes</td>
<td>取值：touch普通文件，directory目录，link软连接，hard硬连接，absent删除；指定对文件操作的类型</td>
</tr>
<tr>
<td>src</td>
<td>no</td>
<td>当state设置为link或者hard时，指定软硬连接的链接源</td>
</tr>
<tr>
<td>force</td>
<td>no</td>
<td>当state&#x3D;link的时候，如果源文件不存在，或者链接文件与其他文件同名时，强制覆盖同名文件或者创建链接文件。</td>
</tr>
<tr>
<td>owner</td>
<td>no</td>
<td>用于指定被操作文件的属主，属主对应的用户必须在远程主机中存在，否则会报错</td>
</tr>
<tr>
<td>group</td>
<td>no</td>
<td>用于指定被操作文件的属组，属组对应的组必须在远程主机中存在，否则会报错。</td>
</tr>
<tr>
<td>mode</td>
<td>no</td>
<td>用于指定被操作文件的权限，如”rw-r-x—“为mode&#x3D;650</td>
</tr>
<tr>
<td>recurse</td>
<td>no</td>
<td>当要操作的文件为目录，将recurse设置为yes，可以递归的修改目录中文件的属性。</td>
</tr>
</tbody></table>
</li>
<li><p>创建文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下创建一个文件，如果testfile文件已经存在，则会更新文件的属性</span></span><br><span class="line">ansible webservers -m file -a &quot;path=/home/student/test2.sh state=touch&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下创建一个目录，如果testdir目录已经存在，则不进行任何操作</span></span><br><span class="line">ansible webservers -m file -a &quot;path=/home/student/test state=directory&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下创建一个软连接文件</span></span><br><span class="line">ansible webservers -m file -a &quot;path=./test3.sh state=link src=./test2.sh&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下创建一个硬连接文件</span></span><br><span class="line">ansible webservers -m file -a &quot;path=./test4.sh state=hard src=./test2.sh&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下创建一个连接文件，链接源不存在，强制创建</span></span><br><span class="line">ansible webservers -m file -a &quot;path=./test5.sh state=link src=./test6.sh force=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在student家目录下删除一个文件</span></span><br><span class="line">ansible webservers -m file -a &quot;path=./test3.sh state=absent&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改文件所属主和所属组：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">通过root用户修改所属文件的所属主</span></span><br><span class="line">ansible webservers -u root -k -m file -a &quot;path=/home/student/test state=touch owner=root&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">通过root用户修改所属文件的所属组</span></span><br><span class="line">ansible webservers -u root -k -m file -a &quot;path=/home/student/test state=touch group=root&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>修改文件权限：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在创建文件时或直接，修改文件的权限</span></span><br><span class="line">ansible webservers -m file -a &quot;path=/home/student/test7.sh state=touch mode=774&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在创建目录时或直接，修改目录的权限，递归的修改目录下的文件权限</span></span><br><span class="line">ansible webservers -m file -a &quot;path=/home/student/test state=touch mode=774 recurse=true&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="copy模块："><a href="#copy模块：" class="headerlink" title="copy模块："></a>copy模块：</h3><ul>
<li><p>将ansible主机上的文件拷贝到远程主机中</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必须</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>src</td>
<td>no</td>
<td>用于指定需要copy的文件或目录，src与content两个参数必有其一，否则会报错。</td>
</tr>
<tr>
<td>dest</td>
<td>yes</td>
<td>用于指定文件将被拷贝到远程主机的哪个目录中</td>
</tr>
<tr>
<td>content</td>
<td>no</td>
<td>指定文件内容，src与content两个参数必有其一，否则会报错。</td>
</tr>
<tr>
<td>force</td>
<td>no</td>
<td>当远程主机的目标路径中已经存在同名文件，并且与ansible主机中的文件内容不同时，是否强制覆盖，<strong>默认值为yes</strong></td>
</tr>
<tr>
<td>backup</td>
<td>no</td>
<td>当远程主机的目标路径中已经存在同名文件，并且与ansible主机中的文件内容不同时，是否对远程主机的文件进行备份（备份为原文件名+修改时间的格式）</td>
</tr>
<tr>
<td>owner</td>
<td>no</td>
<td>指定文件拷贝到远程主机后的属主</td>
</tr>
<tr>
<td>group</td>
<td>no</td>
<td>指定文件拷贝到远程主机后的属组</td>
</tr>
<tr>
<td>mode</td>
<td>no</td>
<td>指定文件拷贝到远程主机后的权限，如”rw-r-x—“为mode&#x3D;650</td>
</tr>
</tbody></table>
</li>
<li><p>复制，并覆盖：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">复制ansible主机上的文件到远程主机上</span></span><br><span class="line">ansible webservers -m copy -a &quot;src=test1.sh dest=./&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>复制，并不覆盖：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">复制ansible主机上的文件到远程主机上，同名且内容不相同时不覆盖</span></span><br><span class="line">ansible webservers -m copy -a &quot;src=test1.sh dest=./ force=no&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建 &#x2F; 直接覆盖文件编辑内容:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">在远程主机上创建文件，并复制内容到文件中；如果存在文件内容则覆盖</span></span><br><span class="line">ansible webservers -m copy -a &quot;content=&#x27;this\nis\nworld&#x27; dest=./test8.sh&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>文件存在且内容不同时，备份文件再复制：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将原文件重命名为其他名字后，再复制ansible主机的文件</span></span><br><span class="line">ansible webservers -m copy -a &quot;src=test8.sh dest=./ backup=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>复制文件时，改变远程被复制文件的所属主和所属组：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m copy -a &quot;src=test8.sh dest=./ owner=root&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>复制文件时，改变远程被复制文件的权限：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m copy -a &quot;src=test8.sh dest=./ mode=774&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="fetch模块："><a href="#fetch模块：" class="headerlink" title="fetch模块："></a>fetch模块：</h3><ul>
<li><p>将远程主机上的文件拉取到ansible主机中</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>dest</td>
<td>yes</td>
<td>保存在本机主机的文件路径，如果是多个远程主机将以主机名形式分开保存</td>
</tr>
<tr>
<td>src</td>
<td>yes</td>
<td>远程主机的文件路径，会保存src指定的整个路径</td>
</tr>
<tr>
<td>flat</td>
<td>no</td>
<td>yes不按照src的指定的路径来创建目录，默认no</td>
</tr>
</tbody></table>
</li>
<li><p>示例：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">保存远程主机中主机名/home目录下的文件到本机</span></span><br><span class="line">ansible webservers -uroot -k -m fetch -a &quot;src=/home/student/test4.sh dest=/root/test&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">保存远程主机找中test4.sh文件的文件到本机</span></span><br><span class="line">ansible webservers -uroot -k -m fetch -a &quot;src=/home/student/test4.sh dest=/root/test/</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="synchronize模块："><a href="#synchronize模块：" class="headerlink" title="synchronize模块："></a>synchronize模块：</h3><ul>
<li><p>synchronize 基于rsync命令批量同步文件；使用这个模块的时候，必须保证远程服务器上有rsync这个命令 </p>
</li>
<li><p>作用是推送和拉取，相当于copy模块和fetch模块的集合</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>src</td>
<td>yes</td>
<td>指定源文件路径</td>
</tr>
<tr>
<td>dest</td>
<td>yes</td>
<td>指定目标文件路径</td>
</tr>
<tr>
<td>archive</td>
<td>no</td>
<td>是否采用归档模式同步,保证源文件和目标文件属性一致</td>
</tr>
<tr>
<td>rsync_opts</td>
<td>no</td>
<td>使用rsync参数</td>
</tr>
<tr>
<td>mode</td>
<td>no</td>
<td>synchronize的类型，pull拉取，push推送；默认push</td>
</tr>
<tr>
<td>–exclude&#x3D;*.log</td>
<td>no</td>
<td>此处为忽略什么的文件，必须和rsync_opts一起使用</td>
</tr>
<tr>
<td>delete</td>
<td>no</td>
<td>删除不存在的文件（⽬标端如果⽐源端⽂件多，则删除这些多出来的⽂件），默认no</td>
</tr>
</tbody></table>
</li>
<li><p>安装rsync：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible all -m yum -a &#x27;name=rsync state=present&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>从远端拉去文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m synchronize -a &quot;src=/etc/hosts dest=/root/test mode=pull&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>将本地某目录下的文件，除去.txt结尾的文件且保持文件见属性一致的同步到远程主机上</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m synchronize -a &quot;src=/root/test/ dest=/home/student/test archive=yes delete=yes rsync_opts=--exclude=*.txt&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="blockinfile模块："><a href="#blockinfile模块：" class="headerlink" title="blockinfile模块："></a>blockinfile模块：</h3><ul>
<li><p>blockinfile模块可以帮助我们在指定的文件中<strong>插入”一段文本”<strong>，这段文本是</strong>被标记过的</strong></p>
</li>
<li><p>换句话说就是，我们在这段文本上做了记号，以便在以后的操作中可以通过”标记”找到这段文本，然后修改或者删除它.</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>path</td>
<td>yes</td>
<td>指定要操作的文件</td>
</tr>
<tr>
<td>block</td>
<td>yes</td>
<td>此参数用于指定我们想要操作的那”一段文本”，别名叫”content”</td>
</tr>
<tr>
<td>marker</td>
<td>no</td>
<td>自定义”标记”，格式marker&#x3D;#{mark}test，效果# BEGIN test和# END test</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>present执行插入操作或更新操作，absent：从文件中删除对应标记的段落，默认present</td>
</tr>
<tr>
<td>insertafter</td>
<td>no</td>
<td>值BOF：指定插入某一行后面的行数；也可插入某一个正则表达式行的后面</td>
</tr>
<tr>
<td>insertbefore</td>
<td>no</td>
<td>值EOF：指定插入某一行前面的行数，也可插入某一个正则表达式行的前面</td>
</tr>
<tr>
<td>backup</td>
<td>no</td>
<td>是否在修改文件之前对文件进行备份</td>
</tr>
<tr>
<td>create</td>
<td>no</td>
<td>当要操作的文件并不存在时，是否创建对应的文件</td>
</tr>
</tbody></table>
</li>
<li><p>在远程主机的文件内容末尾添加一行文本，使用默认标记</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=./test/hosts block=&#x27;8.130.17.95 www.qv123.top&#x27;&quot;</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">文件内容</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">BEGIN ANSIBLE MANAGED BLOCK</span></span><br><span class="line">8.130.17.95 www.qv123.top</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">END ANSIBLE MANAGED BLOCK</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在远程主机的文件内容末尾添加一行文本，使用自定义标记</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=./test/hosts block=&#x27;systemctl restart httpd\nsystemctl restart chrony&#x27; marker=&#x27;#&#123;mark&#125; test1&#x27;&quot;</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">文件内容</span></span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">BEGIN test1</span></span><br><span class="line">systemctl restart httpd</span><br><span class="line">systemctl restart chrony</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">END test1</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>当文本块标记已存在，但再次编辑内容不同时，会覆盖原标记中的内容</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;systemctl restart redis&#x27; marker=&#x27;#&#123;mark&#125; test1&#x27;&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除对应标记文本块</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansbile webservers -m blockinfile -a &quot;path=~/test/hosts  marker=&#x27;#&#123;mark&#125; test1&#x27; state=absent&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>将文本块插入到文档的开头，可以使用insertbefore参数，将其值设置为BOF，BOF表示Begin Of File</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;192.168.152 wangxuan2.com&#x27; marker=&#x27;#&#123;mark&#125; test2&#x27; insertbefore=BOF&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>如果使用如下命令，表示将文本块插入到文档的结尾，与默认操作相同，将insertafter参数设置为EOF表示End Of File</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;192.168.152 wangxuan2.com&#x27; marker=&#x27;#&#123;mark&#125; test2&#x27; insertafter=EOF&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用如下命令表示使用正则表达式匹配行，将文本块插入到 “以#END test2开头的行 “ 之后</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;192.168.152 wangxuan2.com&#x27; marker=&#x27;#&#123;mark&#125; test3&#x27; insertbefore=&#x27;^#END test2&#x27;&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用backup参数，可以在操作修改文件之前，对文件进行备份，备份的文件会在原文件名的基础上添加时间戳</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;192.168.152 wangxuan2.com&#x27; marker=&#x27;#&#123;mark&#125; test4&#x27; backup=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用create参数，如果指定的文件不存在，则创建它</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m blockinfile -a &quot;path=~/test/hosts block=&#x27;192.168.152 wangxuan2.com&#x27; marker=&#x27;#&#123;mark&#125; test4&#x27; create=yes&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="lineinfile模块："><a href="#lineinfile模块：" class="headerlink" title="lineinfile模块："></a>lineinfile模块：</h3><ul>
<li><p>lineinfile模块，确保”<strong>某一行文本</strong>“存在于指定的文件中，或者确保从文件中删除指定的”文本”（即确保指定的文本不存在于文件中），还可以根据正则表达式，替换”某一行文本”。</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>path</td>
<td>yes</td>
<td>指定要操作的文件</td>
</tr>
<tr>
<td>line</td>
<td>no</td>
<td>指定文本内容</td>
</tr>
<tr>
<td>regexp</td>
<td>no</td>
<td>使用正则表达式匹配对应的行，当替换文本时，多行文本被匹配，则最后面被匹配到的行文本被替换；当删除文本时，多行文本被匹配，这些行都会被删除。</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>present执行插入操作或更新操作，absent：从文件中删除对应标记的段落，默认present</td>
</tr>
<tr>
<td>backrefs</td>
<td>no</td>
<td>backrefs&#x3D;yes表示开启后向引用</td>
</tr>
<tr>
<td>insertafter</td>
<td>no</td>
<td>插入到“指定的行”之后，EOF插入到文档的末尾，正则表达式表示将文本插入到匹配的行之后，默认EOF</td>
</tr>
<tr>
<td>insertbefore</td>
<td>no</td>
<td>插入到“指定的行”之前，BOF插入到文档的头部，正则表达式表示将文本插入到匹配的行之后</td>
</tr>
<tr>
<td>backup</td>
<td>no</td>
<td>是否在修改文件之前对文件进行备份。</td>
</tr>
<tr>
<td>create</td>
<td>no</td>
<td>当要操作的文件并不存在时，是否创建对应的文件</td>
</tr>
</tbody></table>
</li>
<li><p>文档尾插入内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m lineinfile -a &quot;path=~/test/hosts line=&#x27;this is world1&#x27;&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>regexp支持正则符匹配可以将匹配的行进行替换，匹配到多行时，最后面被匹配到的行文本被替换；当没有匹配到内容时，插入文档末尾。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m lineinfile -a &quot;path=~/test/hosts regexp=&#x27;^#&#x27; line=&#x27;zhanglin is dead&#x27;&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>backrefs&#x3D;yes，当没有匹配到指定行则不做任何更改</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m lineinfile -a &quot;path=~/test/hosts regexp=&#x27;^#&#x27; line=&#x27;zhanglin is dead&#x27; backrefs=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>匹配指定内容的行删除（若多行匹配全部删除）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m lineinfile -a &quot;path=~/test/hosts regexp=&#x27;^#&#x27; state=absent&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="unarchive模块："><a href="#unarchive模块：" class="headerlink" title="unarchive模块："></a>unarchive模块：</h3><ul>
<li><p>作用：解包和解压缩</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>copy</td>
<td>no</td>
<td>yes将ansible主机上的压缩包传到远程主机后解压缩至特定目录，no将远程主机上的某个压缩包解压缩到指定路径下；默认yes</td>
</tr>
<tr>
<td>remote_src</td>
<td>no</td>
<td>yes表示在远程主机不在ansible主机，no表示文件在ansible主机上</td>
</tr>
<tr>
<td>src</td>
<td>yes</td>
<td>源路径，可以是ansible主机上的路径；也可以是远程主机上的路径，如果是远程主机上的路径，则需要设置copy&#x3D;no</td>
</tr>
<tr>
<td>dest</td>
<td>yes</td>
<td>远程主机上的目标路径</td>
</tr>
<tr>
<td>mode</td>
<td>no</td>
<td>设置解压缩后的文件权限</td>
</tr>
</tbody></table>
</li>
<li><p>解压远程主机上的压缩文件到指定目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m unarchive -a &quot;src=./myShell.tar.gz dest=./ copy=no&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>将ansible主机上的压缩包上传到远程主机后并解压到指定目录，修改压缩后的文件权限；上传的压缩文件将被删除。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m unarchive -a &quot;src=./myShell.tar.gz dest=./ mode=774&quot;</span><br><span class="line">ansible webservers -m unarchive -a &quot;src=./myShell.tar dest=./ mode=774&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="Archive模块："><a href="#Archive模块：" class="headerlink" title="Archive模块："></a>Archive模块：</h3><ul>
<li><p>作用：打包和压缩</p>
</li>
<li><p>将远程主机上的文件压缩，并修改所属主和文件权限</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m archive -a &quot;path=./myShell dest=./myShell.tar.gz owner=root mode=777&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="3-计划任务模块：cron模块"><a href="#3-计划任务模块：cron模块" class="headerlink" title="3.计划任务模块：cron模块"></a>3.计划任务模块：cron模块</h3><ul>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>backup</td>
<td></td>
<td>对远程主机上的原任务计划内容修改之前做备份</td>
</tr>
<tr>
<td>cron_file</td>
<td></td>
<td>如果指定该选项，则用该文件替换远程主机上的cron.d目录下的用户的任务计划</td>
</tr>
<tr>
<td>day</td>
<td></td>
<td>天，取值范围（1-31，<em>，</em>&#x2F;2）</td>
</tr>
<tr>
<td>hour</td>
<td></td>
<td>小时，取值范围（0-23，<em>，</em>&#x2F;2）</td>
</tr>
<tr>
<td>minute</td>
<td></td>
<td>分钟，取值范围（0-59，*， *&#x2F;2）</td>
</tr>
<tr>
<td>month</td>
<td></td>
<td>月，取值范围（1-12，<em>，</em>&#x2F;2）</td>
</tr>
<tr>
<td>weekday</td>
<td></td>
<td>周</td>
</tr>
<tr>
<td>job</td>
<td></td>
<td>要执行的任务，依赖于state&#x3D;present</td>
</tr>
<tr>
<td>name</td>
<td></td>
<td>该任务的描述</td>
</tr>
<tr>
<td>special_time</td>
<td></td>
<td>指定什么时候执行，参数：reboot,yearly（每年），annually，monthly,weekly,daily,hourly</td>
</tr>
<tr>
<td>state</td>
<td></td>
<td>确认该任务计划是创建还是删除，prsent创建，absent删除；默认pr</td>
</tr>
<tr>
<td>user</td>
<td></td>
<td>以哪个用户的身份执行</td>
</tr>
</tbody></table>
</li>
<li><p>创建任务：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">内天1点5分查看一下家目录</span></span><br><span class="line">ansible webservers -m cron -a &quot;name=ll minute=5 hour=1 job=&#x27;ls -l ./&#x27;&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">修改计划之前备份</span></span><br><span class="line">ansible dong -m cron -a &quot;name=ll minute=5 hour=3 job=&#x27;ls -l ./&#x27; backup=yes&quot;</span><br><span class="line">192.168.169.162 | CHANGED =&gt; &#123;</span><br><span class="line">    &quot;ansible_facts&quot;: &#123;</span><br><span class="line">        &quot;discovered_interpreter_python&quot;: &quot;/usr/bin/python&quot;</span><br><span class="line">    &#125;, </span><br><span class="line">    &quot;backup_file&quot;: &quot;/tmp/crontabh5DeZQ&quot;, 					# 备份文件路径</span><br><span class="line">    &quot;changed&quot;: true, </span><br><span class="line">    &quot;envs&quot;: [], </span><br><span class="line">    &quot;jobs&quot;: []</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看任务：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m shell -a &quot;crontab -l&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除任务：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m cron -a &quot;name=ll state=absent&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="4-两个用户模块："><a href="#4-两个用户模块：" class="headerlink" title="4.两个用户模块："></a>4.两个用户模块：</h3><ul>
<li><p>user模块：</p>
<ul>
<li><p>实现用户账号管理。</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>yes</td>
<td>指定操作用户名</td>
</tr>
<tr>
<td>uid</td>
<td>no</td>
<td>指定用户的uid</td>
</tr>
<tr>
<td>group</td>
<td>no</td>
<td>所属组</td>
</tr>
<tr>
<td>groups</td>
<td>no</td>
<td>附加组</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>状态，prsent创建，absent删除；默认prsent</td>
</tr>
<tr>
<td>home</td>
<td>no</td>
<td>指定用户家目录</td>
</tr>
<tr>
<td>remove</td>
<td>no</td>
<td>yes是否删除家目录，no不删除家目录；默认no</td>
</tr>
<tr>
<td>password</td>
<td>no</td>
<td>指定密码（为用python的crypt命令加密后的值）</td>
</tr>
<tr>
<td>shell</td>
<td>no</td>
<td>shell类型，&#x2F;sbin&#x2F;nologin不能登录，默认是bash</td>
</tr>
</tbody></table>
</li>
<li><p>创建用户tom，密码为123 （密码需要使用双引号引用）</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@quruixiang ~]# python3</span><br><span class="line">Python 3.6.8 (default, Sep  9 2021, 07:49:02) </span><br><span class="line">[GCC 8.5.0 20210514 (Red Hat 8.5.0-3)] on linux</span><br><span class="line">Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.</span><br><span class="line"><span class="meta prompt_">&gt;</span><span class="language-bash">&gt;&gt; import crypt</span></span><br><span class="line"><span class="meta prompt_">&gt;</span><span class="language-bash">&gt;&gt; crypt.crypt(<span class="string">&#x27;123&#x27;</span>)</span></span><br><span class="line">&#x27;$6$GM1DTS2hFMz68Vuh$WLxu57RzlUgZBqdnfwJb6AKJmw8Aq1HC6WwvrsFwNStaOWJZoP299AXphfQcFP8Xo98MXecYOtPYvp1wGVpds.&#x27;</span><br><span class="line">[root@quruixiang ~]# ansible webservers -u root -k -m user -a &#x27;name=tom password=&quot;$6$GM1DTS2hFMz68Vuh$WLxu57RzlUgZBqdnfwJb6AKJmw8Aq1HC6WwvrsFwNStaOWJZoP299AXphfQcFP8Xo98MXecYOtPYvp1wGVpds.&quot;&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建用户bob，指定所属组和附加组</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m user -a &quot;name=test8 group=tom groups=test1&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除用户，连同家目录一起：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m user -a &quot;name=test2 state=absent remove=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>为bob用户生成密钥对</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m user -a &quot;name=test8 generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><p>group模块：</p>
<ul>
<li><p>管理用户组</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>yes</td>
<td>用于指定要操作的组名称</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>用于指定组的状态，present创建，absent删除，默认为present,</td>
</tr>
<tr>
<td>gid</td>
<td>no</td>
<td>用于指定组的gid</td>
</tr>
<tr>
<td>system</td>
<td>no</td>
<td>系统组</td>
</tr>
</tbody></table>
</li>
<li><p>创建一个用户组，并指定gid：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m group -a &quot;name=wangxuan gid=2000&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除一个用户组：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m group -a &quot;name=wangxuan state=absent&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="5二个软件包管理模块："><a href="#5二个软件包管理模块：" class="headerlink" title="5二个软件包管理模块："></a>5二个软件包管理模块：</h3><ul>
<li><h3 id="yum-repository模块："><a href="#yum-repository模块：" class="headerlink" title="yum_repository模块："></a>yum_repository模块：</h3><ul>
<li><p>yum_repository 模块可以帮助我们管理远程主机上的 yum 仓库 </p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>yes</td>
<td>用于指定要操作的唯一的仓库ID，也就是”.repo”配置文件中每个仓库对应的”中括号”内的仓库ID。</td>
</tr>
<tr>
<td>baseurl</td>
<td>no</td>
<td>此参数用于设置 yum 仓库的 baseurl</td>
</tr>
<tr>
<td>description</td>
<td>no</td>
<td>此参数用于设置仓库的注释信息，也就是”.repo”配置文件中每个仓库对应的”name字段”对应的内容。</td>
</tr>
<tr>
<td>file</td>
<td>no</td>
<td>此参数用于设置仓库的配置文件名称，默认名name</td>
</tr>
<tr>
<td>enabled</td>
<td>no</td>
<td>此参数用于设置是否激活对应的 yum 源，默认yes激活</td>
</tr>
<tr>
<td>gpgcheck</td>
<td>no</td>
<td>此参数用于设置是否开启 rpm 包验证功能，默认值为 no</td>
</tr>
<tr>
<td>gpgkey</td>
<td>no</td>
<td>当 gpgcheck 参数设置为 yes 时，需要使用此参数指定验证包所需的公钥</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>absent，表示删除对应的 yum 源；默认值为 present表示创建或修改</td>
</tr>
</tbody></table>
</li>
<li><p>向远程主机上添加yum源文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m yum_repository -a &quot;name=&#x27;mongodb&#x27; description=&#x27;mongodb&#x27; baseurl=&#x27;https://mirrors.aliyun.com/mongodb/yum/redhat/8Server/mongodb-org/4.4/x86_64/&#x27; gpgcheck=no file=mongo&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>删除远程主机上的yum源文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m yum_repository -a &quot;name=mongodb file=mongo state=absent&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="yum模块："><a href="#yum模块：" class="headerlink" title="yum模块："></a>yum模块：</h3><ul>
<li><p>安装软件包</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td>yes</td>
<td>用于指定需要管理的软件包</td>
</tr>
<tr>
<td>state</td>
<td>no</td>
<td>用于指定软件包的状态，present安装，latest安装最新版，installed已安装，absent删除；默认present</td>
</tr>
<tr>
<td>enablerepo</td>
<td></td>
<td>用于指定安装软件包时临时启用的 yum 源</td>
</tr>
<tr>
<td>disablerepo</td>
<td></td>
<td>用于指定安装软件包时临时禁用的 yum 源</td>
</tr>
<tr>
<td>disable_gpg_check</td>
<td></td>
<td>yes为禁用对 rpm 包的公钥 gpg 验证。默认值为 no</td>
</tr>
</tbody></table>
</li>
<li><p>通过yum安装httpd服务器</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m yum -a &quot;name=httpd disable_gpg_check=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>在 ansible-demo3 主机上安装 telnet 时，多个源中都有 telnet，安装时临时禁用 local 源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible all -m yum -a &#x27;name=telnet disable_gpg_check=yes  disablerepo=local&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>在 ansible-demo3 主机上安装 telnet 时，不确定 local 源是否启用，安装时临时启用 local 源</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible all -m yum -a &#x27;name=telnet disable_gpg_check=yes  enablerepo=local&#x27; </span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="6-服务进程模块：Service-x2F-systemd模块"><a href="#6-服务进程模块：Service-x2F-systemd模块" class="headerlink" title="6.服务进程模块：Service&#x2F;systemd模块"></a>6.服务进程模块：Service&#x2F;systemd模块</h3><ul>
<li><p>用于操作服务进程</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>name</td>
<td></td>
<td>此参数用于指定需要操作的服务名称</td>
</tr>
<tr>
<td>state</td>
<td></td>
<td>指定服务的状态，started启动，stopped停止，restarted重启，reloaded重载配置</td>
</tr>
<tr>
<td>enabled</td>
<td></td>
<td>yes将服务设置为开机 启动项，默认no</td>
</tr>
<tr>
<td>arguments</td>
<td></td>
<td>给命令提供一些选项</td>
</tr>
<tr>
<td>runlevel</td>
<td></td>
<td>运行等级</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
</li>
<li><p>重启httpd服务：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m service -a &quot;name=httpd state=restarted&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>启动httpd服务并设置开机重启：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m service -a &quot;name=httpd state=started enabled=yes&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>查看服务：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -a &quot;systemctl status redis&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="7-两个防火墙模块："><a href="#7-两个防火墙模块：" class="headerlink" title="7.两个防火墙模块："></a>7.两个防火墙模块：</h3><ul>
<li><h3 id="firewalld-模块："><a href="#firewalld-模块：" class="headerlink" title="firewalld 模块："></a>firewalld 模块：</h3><ul>
<li><p>控制流量的进出</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>可选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>service</td>
<td></td>
<td>指定服务</td>
</tr>
<tr>
<td>state</td>
<td></td>
<td>指防火墙策略状态，present添加，absent删除，enable开机启动，disable开机禁止</td>
</tr>
<tr>
<td>immediate</td>
<td></td>
<td>立即启用</td>
</tr>
<tr>
<td>port</td>
<td></td>
<td>端口</td>
</tr>
<tr>
<td>permanent</td>
<td></td>
<td>是否永久生效</td>
</tr>
<tr>
<td>rich_rule</td>
<td></td>
<td>富规则</td>
</tr>
<tr>
<td>source</td>
<td></td>
<td>源</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
</li>
<li><p>防火墙必须选启动</p>
</li>
<li><p>允许http协议服务通过，永久有效，立刻生效，开机自启：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m firewalld -a &quot;service=http permanent=true immediate=true state=enabled&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>允许80&#x2F;tcp端口通过，永久有效，立刻生效，开机自启：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m firewalld -a &quot;port=80/tcp permanent=true immediate=true state=enabled&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>富规则：允许源地址192.168.150.0&#x2F;24网段http服务通过，永久有效，立刻生效，开机自启</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m firewalld -a &#x27;rich_rule=&quot;rule family=ipv4 source address=192.168.150.0/24 service name=http accept&quot; permanent=true immediate=true state=enabled&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>富规则：将443端口的数据转发到8443端口上，，永久有效，立刻生效，开机自启</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m firewalld -a &#x27;rich_rule=&quot;rule family=ipv4 forward-port port=443 protocol=tcp to-port=8443&quot; permanent=true immediate=true state=enabled&#x27;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="selinux模块："><a href="#selinux模块：" class="headerlink" title="selinux模块："></a>selinux模块：</h3><ul>
<li><p>管理远端主机的 SELINUX ；</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>可选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>state</td>
<td></td>
<td>enforcing禁止模式、permissive宽容模式、disabled关闭</td>
</tr>
<tr>
<td>policy</td>
<td></td>
<td>targeted针对网络服务限制较多，针对本机限制较少，是<strong>默认的策略</strong>；strict限制方面较为严格</td>
</tr>
</tbody></table>
</li>
<li><p>将setlinux设置为enforcing，策略为targeted</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m selinux -a &#x27;state=enforcing policy=targeted&#x27;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="8-配置网络模块：nmcli模块"><a href="#8-配置网络模块：nmcli模块" class="headerlink" title="8.配置网络模块：nmcli模块"></a>8.配置网络模块：nmcli模块</h3><ul>
<li><p>nmcli模块支持管理网络连接和设备，此模块支持配置网络接口组合和绑定，以及ipv4和ipv6寻址</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>conn_name</td>
<td>必选</td>
<td>配置连接的网卡名称</td>
</tr>
<tr>
<td>autoconnect</td>
<td></td>
<td>启用在引导时自动激活连接</td>
</tr>
<tr>
<td>dns4</td>
<td></td>
<td>配置iPV4的dns服务器(最多3个)</td>
</tr>
<tr>
<td>gw4</td>
<td></td>
<td>为接口配置ipv4网关</td>
</tr>
<tr>
<td>Ifname</td>
<td></td>
<td>要绑定到连接的接口</td>
</tr>
<tr>
<td>Ip4</td>
<td></td>
<td>接口的ip地址</td>
</tr>
<tr>
<td>State</td>
<td></td>
<td>present启用或absent禁用网络接口</td>
</tr>
<tr>
<td>Type</td>
<td></td>
<td>设备或网络链接的类型</td>
</tr>
</tbody></table>
</li>
<li><p>给网卡ens160修改IP地址</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m nmcli -a &quot;conn_name=ens160 ip4=&#x27;192.168.178.151/24,192.168.178.152/24&#x27; state=present type=ethernet&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="9-主机名模块：hostname模块"><a href="#9-主机名模块：hostname模块" class="headerlink" title="9.主机名模块：hostname模块"></a>9.主机名模块：hostname模块</h3><ul>
<li><p>修改主机名</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible 192.168.100.18 -m hostname -a &#x27;name=node18.magedu.com&#x27;</span><br></pre></td></tr></table></figure></li>
</ul>
<h3 id="10-两个上传下载模块："><a href="#10-两个上传下载模块：" class="headerlink" title="10.两个上传下载模块："></a>10.两个上传下载模块：</h3><ul>
<li><h3 id="get-url-模块："><a href="#get-url-模块：" class="headerlink" title="get_url 模块："></a>get_url 模块：</h3><ul>
<li><p>该模块主要用于从http、ftp、https服务器上下载文件（类似于wget）</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>可选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>url</td>
<td>yes</td>
<td>下载的URL</td>
</tr>
<tr>
<td>dest</td>
<td>yes</td>
<td>下载到的路径位置</td>
</tr>
<tr>
<td>sha256sum</td>
<td></td>
<td>true下载完成后进行sha256 check</td>
</tr>
<tr>
<td>timeout</td>
<td></td>
<td>载超时时间，默认10s</td>
</tr>
<tr>
<td>url<em>password、url</em>username</td>
<td></td>
<td>主要用于需要用户名密码进行验证的情况</td>
</tr>
<tr>
<td>use_proxy</td>
<td></td>
<td>是否使用代理，代理需事先在环境变更中定义</td>
</tr>
<tr>
<td>owner</td>
<td></td>
<td>指定属主</td>
</tr>
<tr>
<td>group</td>
<td></td>
<td>指定属组</td>
</tr>
</tbody></table>
</li>
<li><p>从网站上下载文件，并修改文件的属主和属组：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m get_url -a &quot;dest=/home/student/test url=http://rpmfind.net/linux/epel/8/Everything/x86_64/Packages/s/sl-5.02-1.el8.x86_64.rpm owner=root group=root&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="uri模块："><a href="#uri模块：" class="headerlink" title="uri模块："></a>uri模块：</h3><ul>
<li><p>如同curl命令</p>
</li>
<li><p>curl命令是一个网络工具，其主要作用是通过http、https、ftp等方式下载&#x2F;上传文件</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>可选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>url</td>
<td></td>
<td>指明请求的url的路径</td>
</tr>
<tr>
<td>user</td>
<td></td>
<td>如果请求的url需要认证，则认证的用户名是什么</td>
</tr>
<tr>
<td>password</td>
<td></td>
<td>如果请求的url需要认证，则认证的密码是什么</td>
</tr>
<tr>
<td>method</td>
<td></td>
<td>指明请求的方法，如GET、POST…</td>
</tr>
<tr>
<td>body</td>
<td></td>
<td>指明报文中实体部分的内容，一般是POST方法或PUT方法时用到</td>
</tr>
<tr>
<td>HEADER</td>
<td></td>
<td>自定义请求报文中的添加的首部</td>
</tr>
<tr>
<td>return_content</td>
<td></td>
<td>是否将返回主体作为字典中的”content”值返回</td>
</tr>
<tr>
<td>validate_certs</td>
<td></td>
<td>如果“否”，则不会验证 ssl 证书</td>
</tr>
<tr>
<td>Force<em>basic</em>auth</td>
<td></td>
<td></td>
</tr>
</tbody></table>
</li>
<li><p>访问百度，并能获取到百度源码</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -m uri -a &quot;url=https://www.baidu.com return_content=yes&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h3 id="11-四个磁盘管理模块："><a href="#11-四个磁盘管理模块：" class="headerlink" title="11.四个磁盘管理模块："></a>11.四个磁盘管理模块：</h3><ul>
<li><h3 id="parted模块："><a href="#parted模块：" class="headerlink" title="parted模块："></a>parted模块：</h3><ul>
<li><p>事先关机添加一块10G新磁盘</p>
</li>
<li><p>在新硬盘上创建主分区编号1，空间2GB</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m parted -a &quot;device=/dev/nvme0n2 number=1 part_end=2GiB state=present&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="lvg模块："><a href="#lvg模块：" class="headerlink" title="lvg模块："></a>lvg模块：</h3><ul>
<li><p>给nvme0n2p1主分区创建卷组vg1</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible webservers -u root -k -m lvg -a &quot;pvs=/dev/nvme0n2p1 vg=vg1&quot;</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用vgs查看卷组：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vgs</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="lvol模块："><a href="#lvol模块：" class="headerlink" title="lvol模块："></a>lvol模块：</h3><ul>
<li><p>创建逻辑卷512M大小</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible localhost -m lvol -a &#x27;vg=vg1 lv=lv1 size=512&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>对&#x2F;dev&#x2F;nvme0n2p3创建512M的逻辑卷</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible localhost -m lvol -a &#x27;vg=vg1 lv=lv2 size=512  pvs=/dev/nvme0n2p3&#x27;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="fillesystem模块："><a href="#fillesystem模块：" class="headerlink" title="fillesystem模块："></a>fillesystem模块：</h3><ul>
<li><p>创建ext4文件系统 &#x2F;dev&#x2F;sdb1</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible localhost -m filesystem -a &#x27;dev=/dev/nvme0n2p2  fstype=ext4  force=yes&#x27;</span><br></pre></td></tr></table></figure>
</li>
<li><p>对逻辑卷lv1创建xfs文件系统</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansible localhost -m filesystem -a &#x27;dev=/dev/vg1/lv1 fstype=xfs  force=yes&#x27;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
<li><h3 id="mount模块："><a href="#mount模块：" class="headerlink" title="mount模块："></a>mount模块：</h3><ul>
<li><p>配置挂载点</p>
</li>
<li><p>模块参数：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>fstype</td>
<td>yes</td>
<td>挂载文件的类型</td>
</tr>
<tr>
<td>path</td>
<td>yes</td>
<td>挂载点</td>
</tr>
<tr>
<td>opts</td>
<td></td>
<td>传递给mount命令的参数</td>
</tr>
<tr>
<td>src</td>
<td>yes</td>
<td>要挂载的文件系统</td>
</tr>
<tr>
<td>state</td>
<td>yes</td>
<td></td>
</tr>
<tr>
<td>unmounted</td>
<td></td>
<td>卸载</td>
</tr>
</tbody></table>
</li>
<li><p>挂载光盘到&#x2F;media&#x2F;cdrom：mount &#x2F;dev&#x2F;cdrom &#x2F;media&#x2F;cdrom</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ansibleansible webservers -u root -k -m mount -a &quot;src=/dev/cdrom path=/media/cdrom state=present fstype=iso9660&quot;</span><br></pre></td></tr></table></figure>

<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">查看是否成功</span></span><br><span class="line">ansible webservers -u root -k -a &quot;tail -1 /etc/fstab&quot;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="http://example.com">阿尔托莉雅</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://example.com/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/">http://example.com/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Linux/">Linux</a></div><div class="post_share"><div class="social-share" data-image="/images/Otherwallpaper/avatar.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/03/13/3.linux/D2.Ansible%E5%89%A7%E6%9C%AC/" title="Ansible"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">Ansible</div></div></a></div><div class="next-post pull-right"><a href="/2023/03/13/3.linux/C1.git%E5%B7%A5%E5%85%B7/" title="git工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">git工具</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/2023/03/13/3.linux/A1.linux%E5%9F%BA%E7%A1%80/" title="Linux基础"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux基础</div></div></a></div><div><a href="/2023/03/13/3.linux/A2.Linux%E5%88%9D%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux初级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux初级命令</div></div></a></div><div><a href="/2023/03/13/3.linux/A3.Linux%E4%B8%AD%E7%BA%A7%E5%91%BD%E4%BB%A4/" title="Linux中级命令"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Linux中级命令</div></div></a></div><div><a href="/2023/03/13/3.linux/A4.Shell%E8%84%9A%E6%9C%AC/" title="Shell脚本"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Shell脚本</div></div></a></div><div><a href="/2023/03/13/3.linux/B1.Docker%E5%AE%B9%E5%99%A8/" title="Docker容器"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">Docker容器</div></div></a></div><div><a href="/2023/03/13/3.linux/C1.git%E5%B7%A5%E5%85%B7/" title="git工具"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-03-13</div><div class="title">git工具</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/images/Otherwallpaper/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">阿尔托莉雅</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">11</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">4</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://toscode.gitee.com/blue-fantasy" target="_blank" title="Gitee"><i class="fab fa-github"></i></a><a class="social-icon" href="/1095322098@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Ansible%E7%9A%84%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">1.</span> <span class="toc-text">1.Ansible的概念：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-Ansible%E5%BA%94%E7%94%A8%E9%A2%86%E5%9F%9F%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">2.Ansible应用领域：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-Ansible%E6%9E%B6%E6%9E%84%E6%A8%A1%E5%BC%8F%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">3.Ansible架构模式：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-Ansible%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%EF%BC%9A"><span class="toc-number">4.</span> <span class="toc-text">4.Ansible执行过程：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-Ansible%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%9A"><span class="toc-number">5.</span> <span class="toc-text">5.Ansible的特性：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-Ansible%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AE%EF%BC%9A"><span class="toc-number">6.</span> <span class="toc-text">6.Ansible安装与配置：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE%EF%BC%9A"><span class="toc-number">6.1.</span> <span class="toc-text">1.环境配置：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%AE%89%E8%A3%85%EF%BC%9A"><span class="toc-number">6.2.</span> <span class="toc-text">2.安装：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-%E6%B8%85%E5%8D%95%E6%96%87%E4%BB%B6%E6%8C%87%E5%AE%9A%E5%8F%97%E7%AE%A1%E4%B8%BB%E6%9C%BA%EF%BC%9A"><span class="toc-number">7.</span> <span class="toc-text">7.清单文件指定受管主机：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E6%A6%82%E5%BF%B5%EF%BC%9A"><span class="toc-number">7.1.</span> <span class="toc-text">1.概念：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E9%9D%99%E6%80%81%E6%96%87%E4%BB%B6%E6%B8%85%E5%8D%95%EF%BC%9A"><span class="toc-number">7.2.</span> <span class="toc-text">2.静态文件清单：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%9D%99%E6%80%81%E4%B8%BB%E6%9C%BA%E6%B8%85%E5%8D%95%EF%BC%9A"><span class="toc-number">7.3.</span> <span class="toc-text">3.自定义静态主机清单：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-%E7%AE%A1%E7%90%86ansible%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%EF%BC%9A"><span class="toc-number">8.</span> <span class="toc-text">8.管理ansible的配置文件：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-ansible-hoc%E5%91%BD%E4%BB%A4%EF%BC%9A"><span class="toc-number">9.</span> <span class="toc-text">9.ansible-hoc命令：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-%E6%A1%88%E4%BE%8B%EF%BC%9A"><span class="toc-number">10.</span> <span class="toc-text">10.案例：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E4%BD%BF%E7%94%A8%E6%99%AE%E9%80%9A%E7%94%A8%E6%88%B7%E8%BF%9E%E6%8E%A5%EF%BC%9A"><span class="toc-number">10.1.</span> <span class="toc-text">1.使用普通用户连接：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%85%B3%E9%97%AD%E4%B8%BB%E6%9C%BA%E7%A7%98%E9%92%A5%E9%AA%8C%E8%AF%81%EF%BC%9A"><span class="toc-number">10.2.</span> <span class="toc-text">2.关闭主机秘钥验证：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E8%BF%9C%E7%A8%8B%E7%94%A8%E6%88%B7sudo%E6%8F%90%E6%9D%83%EF%BC%9A"><span class="toc-number">10.3.</span> <span class="toc-text">3.远程用户sudo提权：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-ansible-doc%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">11.</span> <span class="toc-text">11.ansible-doc模块：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12-ansible%E6%89%A7%E8%A1%8C%E9%A2%9C%E8%89%B2%EF%BC%9A"><span class="toc-number">12.</span> <span class="toc-text">12.ansible执行颜色：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13-ansible%E7%9A%84%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.</span> <span class="toc-text">13.ansible的模块：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%9B%9B%E4%B8%AA%E5%91%BD%E4%BB%A4%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.1.</span> <span class="toc-text">1.四个命令模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%85%AB%E4%B8%AA%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.2.</span> <span class="toc-text">2.八个文件模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#file%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.3.</span> <span class="toc-text">file模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#copy%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.4.</span> <span class="toc-text">copy模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fetch%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.5.</span> <span class="toc-text">fetch模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#synchronize%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.6.</span> <span class="toc-text">synchronize模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#blockinfile%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.7.</span> <span class="toc-text">blockinfile模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#lineinfile%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.8.</span> <span class="toc-text">lineinfile模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#unarchive%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.9.</span> <span class="toc-text">unarchive模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Archive%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.10.</span> <span class="toc-text">Archive模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E8%AE%A1%E5%88%92%E4%BB%BB%E5%8A%A1%E6%A8%A1%E5%9D%97%EF%BC%9Acron%E6%A8%A1%E5%9D%97"><span class="toc-number">13.11.</span> <span class="toc-text">3.计划任务模块：cron模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E4%B8%A4%E4%B8%AA%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.12.</span> <span class="toc-text">4.两个用户模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5%E4%BA%8C%E4%B8%AA%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%AE%A1%E7%90%86%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.13.</span> <span class="toc-text">5二个软件包管理模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#yum-repository%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.14.</span> <span class="toc-text">yum_repository模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#yum%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.15.</span> <span class="toc-text">yum模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-%E6%9C%8D%E5%8A%A1%E8%BF%9B%E7%A8%8B%E6%A8%A1%E5%9D%97%EF%BC%9AService-x2F-systemd%E6%A8%A1%E5%9D%97"><span class="toc-number">13.16.</span> <span class="toc-text">6.服务进程模块：Service&#x2F;systemd模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-%E4%B8%A4%E4%B8%AA%E9%98%B2%E7%81%AB%E5%A2%99%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.17.</span> <span class="toc-text">7.两个防火墙模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#firewalld-%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.18.</span> <span class="toc-text">firewalld 模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#selinux%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.19.</span> <span class="toc-text">selinux模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-%E9%85%8D%E7%BD%AE%E7%BD%91%E7%BB%9C%E6%A8%A1%E5%9D%97%EF%BC%9Anmcli%E6%A8%A1%E5%9D%97"><span class="toc-number">13.20.</span> <span class="toc-text">8.配置网络模块：nmcli模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-%E4%B8%BB%E6%9C%BA%E5%90%8D%E6%A8%A1%E5%9D%97%EF%BC%9Ahostname%E6%A8%A1%E5%9D%97"><span class="toc-number">13.21.</span> <span class="toc-text">9.主机名模块：hostname模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-%E4%B8%A4%E4%B8%AA%E4%B8%8A%E4%BC%A0%E4%B8%8B%E8%BD%BD%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.22.</span> <span class="toc-text">10.两个上传下载模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#get-url-%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.23.</span> <span class="toc-text">get_url 模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#uri%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.24.</span> <span class="toc-text">uri模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-%E5%9B%9B%E4%B8%AA%E7%A3%81%E7%9B%98%E7%AE%A1%E7%90%86%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.25.</span> <span class="toc-text">11.四个磁盘管理模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#parted%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.26.</span> <span class="toc-text">parted模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#lvg%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.27.</span> <span class="toc-text">lvg模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#lvol%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.28.</span> <span class="toc-text">lvol模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#fillesystem%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.29.</span> <span class="toc-text">fillesystem模块：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#mount%E6%A8%A1%E5%9D%97%EF%BC%9A"><span class="toc-number">13.30.</span> <span class="toc-text">mount模块：</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B3.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20MongDB/" title="NoSQL篇-MongDB数据库">NoSQL篇-MongDB数据库</a><time datetime="2023-03-13T12:32:38.445Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/B2.NoSQL%E6%95%B0%E6%8D%AE%E5%BA%93%20-%20Redis/" title="NoSQL篇-Redis数据库">NoSQL篇-Redis数据库</a><time datetime="2023-03-13T12:32:38.441Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/4.%E6%95%B0%E6%8D%AE%E5%BA%93/A1.MySQL-%E6%AC%A7%E9%B9%8F%E7%AF%87/" title="SQL篇-MySQL数据库">SQL篇-MySQL数据库</a><time datetime="2023-03-13T12:32:38.437Z" title="Created 2023-03-13 20:32:38">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D2.Ansible%E5%89%A7%E6%9C%AC/" title="Ansible">Ansible</a><time datetime="2023-03-13T12:32:23.866Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/03/13/3.linux/D1.Ansible%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E5%B7%A5%E5%85%B7/" title="Ansible基础">Ansible基础</a><time datetime="2023-03-13T12:32:23.861Z" title="Created 2023-03-13 20:32:23">2023-03-13</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 阿尔托莉雅</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>